package cn.tedu.zhxy.service.impl;


import cn.tedu.zhxy.dto.LoginDTO;
import cn.tedu.zhxy.entity.Student;
import cn.tedu.zhxy.mapper.StudentMapper;
import cn.tedu.zhxy.service.StudentService;
import cn.tedu.zhxy.util.MD5;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-07-20
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public Student login(LoginDTO loginDTO) {
        QueryWrapper<Student>  queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",loginDTO.getUsername());
        queryWrapper.eq("password", MD5.encrypt(loginDTO.getPassword()));
        Student student = baseMapper.selectOne(queryWrapper);
        return student;
    }

    @Override
    public IPage<Student> selectList(Page<Student> pageParam, Student student) {
        QueryWrapper  queryWrapper = new QueryWrapper();
        if (!StringUtils.isEmpty(student.getName())){
            queryWrapper.eq("name",student.getName());
        }
        if (!StringUtils.isEmpty(student.getClazzName())){
            queryWrapper.eq("clazz_name",student.getClazzName());
        }
        Page<Student> page = baseMapper.selectPage(pageParam, queryWrapper);
        return page;
    }
}
